package org.wyp.wang;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;

/**
 * Created by lenovo on 2017/6/26.
 */
public class AuthenticateDemo2 {
    public static void main(String[] args){
        Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:authenticate-shiro2.ini");
        SecurityManager securityManager = factory.getInstance();
        SecurityUtils.setSecurityManager(securityManager);
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken("rvp","321");
        try {
            subject.login(token);
        } catch (AuthenticationException e){
            e.printStackTrace();
        }
        System.out.println(subject.isAuthenticated());
        subject.logout();
    }
}
